<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
/**
 * NGMenu Form Field class for the NGMenu component
 */
class JFormFieldWeightValues extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var		string
	 */
	protected $type = 'WeightValues';
 
//	public function getLabel() {
//	}
 
	public function getInput() {
		$app =& JFactory::getApplication();
		$font_family = $app->getUserState('com_ngmenu.font_family');
		$font_family = str_replace('+', ' ', $font_family);
		$font_family = explode('|', $font_family);
		
		$database =& JFactory::getDBO();
		$query = $database->getQuery(true);
		$query->select('variants');
		$query->from('#__ngmenu_fonts');
		$query->where("name='".$font_family[0]."'");
		$database->setQuery($query);
		$database->query();
		$variants = '';
		if($database->getNumRows()){
			$row = $database->loadAssoc();
			$variants = $row['variants'];
		}
		$weightvalues = array();
		if(!empty($variants)){
			$variants_array = explode(',', $variants);
			foreach($variants_array as $variant){
				switch ($variant){
					case '100':
						$value = '100';
						$label = 'ultra-light';
						break;
					case '100italic':
						$value = '100italic';
						$label = 'ultra-light-italic';
						break;
					case '200':
						$value = '200';
						$label = 'light';
						break;
					case '200italic':
						$value = '200italic';
						$label = 'light-italic';
						break;
					case '300':
						$value = '300';
						$label = 'book';
						break;
					case '300italic':
						$value = '300italic';
						$label = 'book-italic';
						break;
					case 'regular':
						$value = '400';
						$label = 'normal';
						break;
					case 'italic':
						$value = '400italic';
						$label = 'normal-italic';
						break;
					case '500':
						$value = '500';
						$label = 'medium';
						break;
					case '500italic':
						$value = '500italic';
						$label = 'medium-italic';
						break;
					case '600':
						$value = '600';
						$label = 'semi-bold';
						break;
					case '600italic':
						$value = '600italic';
						$label = 'semi-bold-italic';
						break;
					case '700':
						$value = '700';
						$label = 'bold';
						break;
					case '700italic':
						$value = '700italic';
						$label = 'bold-italic';
						break;
					case '800':
						$value = '800';
						$label = 'extra-bold';
						break;
					case '800italic':
						$value = '800italic';
						$label = 'extra-bold-italic';
						break;
					case '900':
						$value = '900';
						$label = 'ultra-bold';
						break;
					case '900italic':
						$value = '900italic';
						$label = 'ultra-bold-italic';
						break;
				}
				$weightvalues[] = JHtml::_('select.option', $value, $label);
			}
		}else{
			$weightvalues[] = JHtml::_('select.option', 'normal', JText::_('COM_NGMENU_LIST_VALUES_NORMAL'));
			$weightvalues[] = JHtml::_('select.option', 'bold', JText::_('COM_NGMENU_LIST_VALUES_BOLD'));
			$weightvalues[] = JHtml::_('select.option', 'bolder', JText::_('COM_NGMENU_LIST_VALUES_BOLDER'));
			$weightvalues[] = JHtml::_('select.option', 'lighter', JText::_('COM_NGMENU_LIST_VALUES_LIGHTER'));
		}

		return JHtml::_('select.genericlist', $weightvalues, $this->name, null, 'value', 'text', $this->value);
	}
}
